<template>
  <el-dialog
    title="编辑此栏目"
    :visible.sync="dialogVisible"
    width="40%"
    append-to-body
    :close-on-click-modal="false"
    :lock-scroll="false"
    :show-close="false"
    top="40px"
  >
    <el-form ref="pageForm" label-width="80px">
      <el-form-item label="栏目名称">
        <el-input v-model="name" placeholder="请输入栏目名称" />
      </el-form-item>
      <!-- 添加更多表单项 -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="savePage">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { EventBus } from "@/EventBus"; // 假设EventBus.js位于src目录下

export default {
  data() {
    return {
      dialogVisible: false,
      name: "",
      row: {},
    };
  },

  mounted() {
    this.name = this.row.name;
  },

  methods: {
    visible(row) {
      this.dialogVisible = true;
      this.row = row;
      this.name = row.name;
    },

    hidden() {
      this.dialogVisible = false;
    },
    async savePage() {
      if (!this.name) {
        return this.$message.error("请输入栏目名称");
      }
      const { code } = await this.$fetch.post("/api/directory/update", {
        name: this.name,
        parentId: this.row.parentId,
        level: this.row.level,
        id: this.row.id,
      });
      if (code === 0) {
        EventBus.$emit("menuRefresh");
        this.$message.success("成功");
      }
      this.dialogVisible = false;
    },
  },
};
</script>
